<div class="page-header">
    <h1>
        Withdraw
        <small>
            <i class="icon-double-angle-right"></i>
            Withdraw Through Perfect Money, Ego Pay or PayPal
        </small>
    </h1>
</div>

<?php
if ($this->errmsg) {
    ?>
    <div class="alert alert-danger">
        <button type="button" class="close" data-dismiss="alert">
            <i class="icon-remove"></i>
        </button>

        <strong>
            <i class="icon-remove"></i>
            Error <br>
        </strong>

        <?php echo $this->errmsg; ?>
        <br />
    </div>
    <?php
}

if ($this->msg) {
    ?>
    <div class="alert alert-info">
        <button type="button" class="close" data-dismiss="alert">
            <i class="icon-remove"></i>
        </button>

        <strong>
            <i class="icon-ok"></i>            
        </strong>

        <?php echo $this->msg; ?>
        <br />
    </div>
    <?php
}

if (!$this->msg && !$this->errmsg) {
    ?>

    <div class="row">
        <div class="col-xs-11">
            
                <form id="formWD2" class="form-horizontal" role="form" action="" method="post" onsubmit="return validate(2)">
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label no-padding-right" for="wallet"> Wallet </label>
                                            <div class="col-sm-9">
                                                    <select class="col-sm-5" id="wallet2" name="wallet2" placeholder="Select an Option" required>
                                                        <option value="">Select an Option</option>
                                                        <option value="0">E Wallet</option>
                                                        <!--option value="1">ROI Wallet</option>
                                                        <option value="2">Refferral Wallet</option>
                                                        <option value="3">Binary Wallet</option>
                                                        <option value="4">Shopping Wallet</option-->
                                                </select>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label no-padding-right" for="balance2"> Balance </label>

                                            <div class="col-sm-9">
                                                <input type="text" id="balance2" name="balance2" placeholder="0" class="col-xs-10 col-sm-5" value="<?php echo (isset($this->data["balance2"])) ? $this->data["balance2"] : $this->balance2; ?>" readonly />

                                            </div>
                                        </div>
                                            <div class="form-group">
                                            <label class="col-sm-3 control-label no-padding-right" for="through"> Withdraw Through </label>
                                            <div class="col-sm-9">
                                                    <select class="col-sm-5" id="through" name="through" placeholder="Select an Option" required>
                                                        <option value="">Select an Option</option>
                                                        <option value="2">Perfect Money</option>
                                                        <option value="3">Ego pay</option>
                                                        <option value="4">PayPal</option>
                                                </select>
                                            </div>
                                        </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label no-padding-right" for="amount2"> Amount </label>

                                                <div class="col-sm-9">
                                                    <input type="text" id="amount2" name="amount2" placeholder="Number Only (Ex: 1500000)" class="col-xs-10 col-sm-5" value="<?php if (isset( $this->tarik )) { echo $this->tarik;} ?>" required onkeypress='return validateNumber(event)' />
                                                </div>
                                            </div>
                                            <div class="form-group">
                                                <label class="col-sm-3 control-label no-padding-right" for="acc_num2"> Account No </label>

                                                <div class="col-sm-9">
                                                    <input type="text" id="acc_num2" name="acc_num2" placeholder="Account No" value="<?php echo $this->acc_num; ?>" class="col-xs-10 col-sm-5" required />
                                                </div>
                                            </div>


                                        <div class="form-group">
                                            <label class="col-sm-3 control-label no-padding-right" for="acc_name2"> Account Name/Mail ID</label>

                                            <div class="col-sm-9">
                                                <input type="text" id="acc_name2" name="acc_name2" placeholder="Account Name/Mail ID" class="col-xs-10 col-sm-5" value="<?php echo $this->acc_name; ?>" required />
                                            </div>
                                        </div>

                                        <div class="clearfix form-actions">
                                            <div class="col-md-offset-3 col-md-9">
                                                <input type="hidden" id="minbalance" name="minbalance" value="<?php echo $this->minbalance;?>">
                                                <input type="hidden" id="minwithdraw" name="minwithdraw" value="<?php echo $this->minwithdraw;?>">
                                                <button class="btn btn-success" type="submit">
                                                    <i class="icon-ok bigger-110"></i>
                                                    Submit
                                                </button>

                                                &nbsp; &nbsp; &nbsp;
                                                <button class="btn" type="reset">
                                                    <i class="icon-undo bigger-110"></i>
                                                    Reset
                                                </button>
                                            </div>
                                        </div>
                                        </form>

        
    </div>
</div>


<script>

    // cek wallet Balance
    $("select#wallet").change(function(){
        var wallet = $('#wallet').val();

        $.getJSON("<?php echo $this->url() ?>/../../jsondata/walletbalance",{wallet: wallet}, function(j){
                
                if (wallet == 0) $('#balance').val(j.amount);
                if (wallet == 1) $('#balance').val(j.amount_1);
                if (wallet == 2) $('#balance').val(j.amount_2);
                if (wallet == 3) $('#balance').val(j.amount_3);
                if (wallet == 4) $('#balance').val(j.amount_4);
                  
            });
    });

    $("select#wallet2").change(function(){
        var wallet = $('#wallet2').val();

        $.getJSON("<?php echo $this->url() ?>/../../jsondata/walletbalance",{wallet: wallet}, function(j){
                if (wallet == 0) $('#balance2').val(j.amount);
                if (wallet == 1) $('#balance2').val(j.amount_1);
                if (wallet == 2) $('#balance2').val(j.amount_2);
                if (wallet == 3) $('#balance2').val(j.amount_3);
                if (wallet == 4) $('#balance2').val(j.amount_4);
        });
    });

    /*
    $("select#through").change(function(){

         var thr = $("#through").val();
         var options = '';

         if (thr == 1){
            document.getElementById("bw").className = "accordion-toggle";
            document.getElementById("collapseOne").className = "panel-collapse collapse in";

            document.getElementById("pm").className = "accordion-toggle collapsed";
            document.getElementById("collapseTwo").className = "panel-collapse collapse";
         }else{
            document.getElementById("bw").className = "accordion-toggle collapsed";
            document.getElementById("collapseOne").className = "panel-collapse collapse";

            document.getElementById("pm").className = "accordion-toggle";
            document.getElementById("collapseTwo").className = "panel-collapse collapse in";
         }
         
      });
      */

    function validateNumber(evt) {

        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
        return true;
    }

    
    function validate(through) {

        var msg = "";
        var amount = 0;
        var balance = 0;
        var minwithdraw = eval($('#minwithdraw').val());
        var minBalance = eval($('#minbalance').val());

        if (through == 1){
            amount = eval($('#amount').val());
            balance = eval($('#balance').val());
        }else{
            amount = eval($('#amount2').val());
            balance = eval($('#balance2').val());
        }

        /*
        if (eval(amount) < eval($('#min_withdraw').val()))
            msg = msg + "* Jumlah Penarikan minimal "+$('#min_withdraw').val()+"<br>";

        if ((eval(balance) - (eval(amount))) < eval($('#min_saldo').val()) || eval(balance) < eval($('#min_saldo').val())){
            
            msg = msg + "* Minimum Saldo tidak mencukupi<br>";
        }
        */

        if (amount > balance)
            msg = msg + "* Withdraw Amount Exceeded<br>";

        if (amount < minwithdraw)
            msg = msg + "* Minimum Withdraw is "+minwithdraw+"<br>";

        if ((balance-amount) < minBalance && minBalance > 0)
            msg = msg + "* Minimum Balance is "+minBalance+"<br>";


        if (msg == "")
            return true;
        else {
            //alert("Data tidak lengkap:\n\n" + msg);
            //$.messager.alert("Data tidak lengkap:\n\n" + msg);
            bootbox.dialog({
                    message: "<span class='bigger-110'>"+msg+"</span>",
                    buttons:
                    {
                            "button" :
                             {
                                    "label" : "<i class='icon-ok'></i> Ok",
                                    "className" : "btn-sm btn-primary",
                                    //"callback": function() {
                                            //Example.show("great success");
                                    //}
                            }
                    }
            });
            return false;
        }
    }


</script>

<?php } ?>